/**
 * Copyright (C), 2021, 因特驰
 * FileName: DemoController
 * Author:   李晋武
 * Date:     2021/7/12 8:05
 * Description:
 * History:
 * 李晋武          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.esc.controller;

import com.esc.model.Demo;
import com.esc.service.DemoService;
import com.esc.util.PageResult;
import com.esc.util.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 〈一句话功能简述〉<br> 
 * 〈〉
 *
 * @author Yun
 * @create 2021/7/12
 * @since 1.0.0
 */
@Controller
@RequestMapping("demo")
public class DemoController {

    @Autowired
    private DemoService demoService;

    //去访问页面
    @GetMapping(value = "show")
    public String show(){
        return "demo/showDemo";
    }

    //分页条件查询Demo集合
    @RequestMapping(value = "queryDemoList")
    @ResponseBody
    PageResult queryDemoList(PageUtil<Demo> pageUtil,Demo demo){
        pageUtil.setT(demo);
        return demoService.queryDemoList(pageUtil);
    }

    //查询单个
    @RequestMapping("queryDemoById")
    public String queryDemoById(Integer demoid, Model model){
        Demo demo = demoService.queryDemoById(demoid);
        model.addAttribute("demo",demo);
        System.out.println(demo);
        return "demo/updateDemo";
    }

    //修改单个Demo
    @PostMapping("updateDemo")
    @ResponseBody
    public void updateDemo(Demo demo){
        demoService.updateDemo(demo);
    }

    //跳转添加页面
    @GetMapping("toAdd")
    public String toAdd(){
        return "demo/addDemo";
    }

    //添加单个Demo
    @PostMapping("addDemo")
    @ResponseBody
    public void addDemo(Demo demo){
        demoService.addDemo(demo);
    }

    //删除单个Demo
    @PostMapping("deleteDemo")
    @ResponseBody
    public void deleteDemo(Integer demoid){
        demoService.deleteDemo(demoid);
    }
}